import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../common/colors.dart';
import '../utils/persisten_storage.dart';

class TopDiaLogPage extends StatefulWidget {
  const TopDiaLogPage({Key? key}) : super(key: key);

  @override
  State<TopDiaLogPage> createState() => _TopDiaLogPageState();
}

class _TopDiaLogPageState extends State<TopDiaLogPage> {



   List dataArr =[];

  int isSelectionIndex = 0;


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getInitData();
  }

  getInitData()async{
    dataArr = await PersistentStorage().getStorage('company_ids_name');
    setState(() {

    });

  }



  @override
  Widget build(BuildContext context) {
    return  GestureDetector(
      onTap: (){
        print('11');
      },
      child:Container(
        margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+kBottomNavigationBarHeight),
        color: Colors.white,
        height: 240,
        child: ListView.builder(itemBuilder: _buildListItem,itemCount: dataArr.length,),
      ),
    );
  }
  Widget _buildListItem(BuildContext context, int index) {
    return GestureDetector(
      onTap: (){
        isSelectionIndex = index;
        setState(() {

        });
      },
      child: Container(
        color: Colors.white,
        alignment: Alignment.center,
        margin: EdgeInsets.only(top: 5),
        height: 53,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              height: 50,
              alignment: Alignment.center,
              // color: Colors.yellow,
              width: Get.width,
              margin: EdgeInsets.only(left: 15,right: 15),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  isSelectionIndex==index?Text(dataArr[index]['name'],style: TextStyle(fontSize: 12,color: AppColor.themeColor),) :
                  Text(dataArr[index],style: TextStyle(fontSize: 12),),
                  isSelectionIndex==index?Icon(Icons.check,size: 15,color:AppColor.themeColor,):
                  Icon(Icons.check,size: 15,color: Colors.transparent,)
                ],
              ),
            ),
            Container(
              color: AppColor.lineColor,
              height: 0.4,


            )
          ],
        ),
      ),
    );
  }
}
